<?php include("../../data/mysql.class.php")?>
<?php
if(isset($_GET["Type"])){
    $Type=$_GET["Type"];
}else{
    $Type="error";
}

$conn=new Mysql();
switch($Type){
    case "prosale":
        $sql="select o.o_pid,p.p_name,count(*) as nums from d_order as o join d_product as p on o.o_pid=p.id where o.o_paystate=1 GROUP BY o.o_pid";
        $cate=array();
        $datau=array();
        $row=$conn->getAll($sql);
            foreach ($row as $key=>$rs){
                $cate[]=$rs["p_name"];
                $datau[]=$rs["nums"];
            }

        $response = array('categories'=>$cate,'data'=>$datau);
        echo json_encode($response);
        break;
    case "worksale":
        $sql="select w.w_name,count(*) as nums from d_worker as w join d_order as o on w.id=o.o_wid where o.o_paystate=1 GROUP BY w.w_name";
        $cate=array();
        $datau=array();
        $row=$conn->getAll($sql);
        $i=0;
        foreach ($row as $key=>$rs){
            $cate[]=$rs["w_name"];
            $datau[]=$rs["nums"];
        }
        $response = array('categories'=>$cate,'data'=>$datau);
        echo json_encode($response);
        break;
    default:
        break;
}
?>